package com.fc.controller;

import com.fc.service.ReplyService;
import com.fc.util.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/")
public class ReplyController {

    @Autowired
    private ReplyService replyService;

    @RequestMapping("/reply.do")
    public String reply(int pid, String content, HttpSession session){
        int sessionUid = (int) session.getAttribute("uid");
        replyService.reply(sessionUid,pid,content);
        return "redirect:toPost.do?pid="+pid;
    }

    @RequestMapping(value = "/mobileReply.do", produces = "text/json;charset=UTF-8")
    @ResponseBody
    public String mobileReply(int pid, String content, int uid){
        replyService.mobileReply(uid,pid,content);
        return new Response().success().code(0).msg("回复成功").toString();
    }

    @RequestMapping("/comment.do")
    public String comment(int pid,int rid, String content, HttpSession session){
        int sessionUid = (int) session.getAttribute("uid");
        replyService.comment(pid,sessionUid,rid,content);
        return "redirect:toPost.do?pid="+pid;
    }
}





